package com.noble.glamour.ui.user.fragment;

import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.noble.glamour.R;
import com.noble.glamour.bean.center.user.detail.UserDetail;
import com.noble.glamour.module.logic.application.ModuleMgr;
import com.noble.glamour.module.util.UIShow;
import com.noble.glamour.ui.utils.NoDoubleClickListener;
import com.noble.library.view.base.BasePanel;

/**
 * 用户中心功能panel
 */
public class UserFragmentFunctionPanel extends BasePanel {

    private RelativeLayout vipPrivilege;
    private ImageView iv_vip_privilege, iv_immortal_verify;
    private TextView tv_vip_title, tv_vip_status, tv_immortal_title, tv_immortal_status, tv_earn_money;

    public UserFragmentFunctionPanel(Context context) {
        super(context);
        setContentView(R.layout.p1_user_fragment_function_panel);

        initView();
    }

    private void initView() {
        RelativeLayout earnMoney = (RelativeLayout) findViewById(R.id.rl_earn_money);
        vipPrivilege = (RelativeLayout) findViewById(R.id.ll_vip_privilege);
        tv_vip_title = (TextView) findViewById(R.id.tv_vip_title);
        iv_vip_privilege = (ImageView) findViewById(R.id.iv_vip_privilege);
        tv_vip_status = (TextView) findViewById(R.id.tv_vip_status);
        tv_immortal_title = (TextView) findViewById(R.id.tv_immortal_title);
        iv_immortal_verify = (ImageView) findViewById(R.id.iv_immortal_verify);
        tv_immortal_status = (TextView) findViewById(R.id.tv_immortal_status);
        tv_earn_money = (TextView) findViewById(R.id.earn_money);

        if (ModuleMgr.getCenterMgr().getMyInfo().isMan()) {
            vipPrivilege.setVisibility(View.VISIBLE);
            if (!ModuleMgr.getCenterMgr().getMyInfo().isVip())
                vipPrivilege.setOnClickListener(clickListener);
        } else {
            earnMoney.setVisibility(View.VISIBLE);
            earnMoney.setOnClickListener(clickListener);
        }

        refreshBadge();
        findViewById(R.id.ll_immortal_verify).setOnClickListener(clickListener);
    }

    /**
     * UserFragmentWealthPanel刷新角标展示
     */
    public void refreshBadge() {
    }

    /**
     * 界面刷新
     */
    public void refreshView(UserDetail userDetail) {
        if (userDetail == null) return;

        // 真人认证
        tv_immortal_status.setText(userDetail.isVerifyAll() ?
                getContext().getResources().getString(R.string.center_phone_has_verify) :
                getContext().getResources().getString(R.string.center_video_to_verify));
        tv_immortal_status.setTextColor(userDetail.isVerifyAll() ? getContext().getResources().getColor(R.color.color_D4D4D4) :
                getContext().getResources().getColor(R.color.color_83A0EC));
        tv_immortal_title.setTextColor(userDetail.isVerifyAll() ? getContext().getResources().getColor(R.color.color_83A0EC) :
                getContext().getResources().getColor(R.color.color_D4D4D4));
        iv_immortal_verify.setSelected(userDetail.isVerifyAll());

        // 男用户更新VIP状态
        if (userDetail.isMan()) {
            tv_vip_status.setText(userDetail.isVip() ?
                    getContext().getResources().getString(R.string.center_vip_left_day) :
                    getContext().getResources().getString(R.string.center_vip_to_open));
            tv_vip_status.setTextColor(userDetail.isVip() ? getContext().getResources().getColor(R.color.color_D4D4D4) :
                    getContext().getResources().getColor(R.color.color_83A0EC));
            tv_vip_title.setTextColor(userDetail.isVip() ? getContext().getResources().getColor(R.color.color_83A0EC) :
                    getContext().getResources().getColor(R.color.color_D4D4D4));
            iv_vip_privilege.setSelected(userDetail.isVip());
            vipPrivilege.setClickable(!userDetail.isVip());
            return;
        }

        tv_earn_money.setText(getContext().getString(R.string.user_info_redbag_num,
                String.valueOf(ModuleMgr.getCenterMgr().getMyInfo().getTodayEarnMoney() / 100f)));
    }

    private final NoDoubleClickListener clickListener = new NoDoubleClickListener() {
        @Override
        public void onNoDoubleClick(View v) {
            switch (v.getId()) {
                case R.id.ll_vip_privilege: // 开通vip
                    UIShow.showOpenVipActivity(getContext());
                    break;

                case R.id.ll_immortal_verify: // 真人认证
                    UIShow.showMyAuthenticationAct((FragmentActivity) getContext(), 103);
                    break;

                case R.id.rl_earn_money:
                    UIShow.showEarnMoney(getContext());
                    break;
            }
        }
    };
}
